var api = require("../../api.js"),
  app = getApp();
const {
  $Toast
} = require('../../iview-weapp/base/index');
Page({
  /** 页面的初始数据 */
  data: {
    /** 您的姓名*/
    contacts: '',
    /** 手机号码 */
    phone: '',
    /** 企业名称 */
    name: '',
    /** 您的职位 */
    post: '',
    /** 办公地址 */
    address: '',
    /** 主营业务 */
    product: '',
    /** 员工人数 */
    workers_no: '',
    /** 年产值 */
    output_value: '',
    /** 问题以及需求 */
    target: '',
    /** 按钮加载中的样式 */
    loading: false,
    /** 需要跳转到问卷 */
    actions: [{
      name: '确定',
      color: '#ed3f14'
    }],
    /** 对话框是否显示 */
    visible: false
  },

  /**  生命周期函数--监听页面加载  */
  onLoad: function (options) {
    /** 调用是否已授权的方法 */
    getApp().is_empower();
  },
  /** 生命周期函数--监听页面显示 */
  onShow: function () {

  },

  /** 输入框的值传输 */
  bind_key_input: function (e) {
    let item = e.currentTarget.dataset.model;
    this.setData({
      [item]: e.detail
    });
  },
  /** 提交信息 */
  sub_form: function () {
    let that = this;
    if (this.data.name != '' && this.data.address != '' && this.data.contacts != '' && this.data.post != '' && this.data.phone != '' && this.data.workers_no != '' && this.data.output_value != '' && this.data.product != '' && this.data.target != '') {
      this.setData({
        loading: true
      });
      var t = new Object();
      t = {
        contacts: this.data.contacts,
        phone: this.data.phone,
        name: this.data.name,
        post: this.data.post,
        address: this.data.address,
        product: this.data.product,
        workers_no: this.data.workers_no,
        output_value: this.data.output_value,
        target: this.data.target,
        openId: getApp().globalData.open_id,
      };
      setTimeout(() => {
        wx.request({
          url: 'http://www.duilusx.com:8080/lianjie/demand/add_enterprise',
          data: t,
          method: "POST",
          header: {
            "content-type": "application/x-www-form-urlencoded"
          },
          success: function (res) {
            that.setData({
              loading: false,
              visible: true
            });
            console.log(res)
          }
        })
      }, 2000);
    } else {
      $Toast({
        content: '请填写完整数据信息',
        type: 'warning'
      });
    }
  },
  ok_click: function () {
    this.setData({
      visible: false
    });
  },
  /** 分享 转发 */
  onShareAppMessage: function (res) {},
});